import java.util.*;

class Person{
    public String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class HashBuck<K,V> {
    static class Node<K, V> {  //KV是定义的两种类型
        public K key;
        public V val;
        public Node<K, V> next;

        public Node(K key, V val) {
            this.key = key;
            this.val = val;
        }
    }

    public Node<K, V>[] array;
    public int usedSize;

    public HashBuck() {
        array = (Node<K, V>[]) new Node[10];
    }

    public void put(K key, V val) {
        int hashCode = key.hashCode();
        int index = hashCode % array.length;
        Node<K, V> cur = array[index];
        while (cur != null) {
            if (cur.key.equals(key)) {//此时的key为引用类型，所以不能用==
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
        Node<K, V> node = new Node<>(key, val);//如果这个节点为空的话就创建一个新的节点
        node.next = array[index];
        array[index] = node;
        usedSize++;
    }

    public V get(K key) {
        int hashCode = key.hashCode();
        int index = hashCode % array.length;
        Node<K, V> cur = array[index];
        while (cur != null) {
            if (cur.key.equals(key)) {
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }

    public int numJewelsInStones(String jewels, String stones) {
        Set<Character> set = new HashSet<>();
        char ch = 0;
        for (int i = 0; i < jewels.length(); i++) {
            ch = jewels.charAt(i);
            set.add(ch);
        }
        int count = 0;
        for (int i = 0; i < stones.length(); i++) {
            if (set.contains(ch)) {
                count++;
            }
        }
        return count;
    }

    public static void func(String str1, String strAct) { //坏键盘打字（牛客题）
        Set<Character> set1 = new HashSet<>();
        for (char ch : strAct.toUpperCase().toCharArray()) { //存储大写的数组
            set1.add(ch);
        }
        Set<Character> set2 = new HashSet<>();
        for (char ch : str1.toUpperCase().toCharArray()) { //存储大写的数组
            if(!set1.add(ch) && !set2.contains(ch)){
                System.out.println(ch);
                set2.add(ch);
            }
        }
    }


    public static void findWords(String[] words){
        Map<String,Integer> map = new HashMap<>();
        for (String word: words) { //遍历words
            if (map.get(word) == null){
                map.put(word,1);
            }else {
                int val = map.get(word);
                map.put(word,val+1); //更新val值
            }
        }
        System.out.println(map);
    }
}
